package com.osgi.desktop.boot;

import com.osgi.desktop.services.ToolBarService;
import com.osgi.desktop.services.ToolBarServiceImpl;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import javax.swing.JFrame;
import javax.swing.JToolBar;
import org.knopflerfish.framework.Framework;
import org.osgi.framework.Constants;

public class Testes extends JFrame {
    private static final long serialVersionUID = 1L;
    public Testes(){
        this.setBounds(200, 200, 500, 500);
        
    }
    public static void main(String args[]) {
        Framework.setProperty(Constants.FRAMEWORK_SYSTEMPACKAGES, "javax.accessibility,javax.net,javax.net.ssl,javax.swing,javax.swing.border,javax.swing.event,javax.swing.filechooser,javax.swing.plaf,javax.swing.plaf.basic,javax.swing.plaf.metal,javax.swing.table,javax.swing.text,javax.swing.tree,com.osgi.desktop.services,com.onetwork.core.actions,com.osgi.desktop.bundle,com.onetwork.core.ui.components,imagens,com.onetwork.core.domain,org.jdesktop.swingx,javax.imageio,javax.management,javax.sql,javax.naming,org.ietf.jgss,javax.crypto.spec,javax.crypto,javax.xml.parsers,org.w3c.dom");
        Framework.setProperty(Constants.EXPORT_PACKAGE, "com.osgi.desktop.ui,com.osgi.desktop.services");
        Framework.setProperty("org.osgi.framework.dir", "fwdir");
        Framework.setProperty("org.knopflerfish.gosg.jars", "jars");
        Framework.setProperty("org.knopflerfish.verbosity", "0");
        try {
            Framework framework = new Framework(new Object());
            framework.launch(0);
            framework.getSystemBundleContext().registerService(ToolBarService.class.getName(), new ToolBarServiceImpl(new JToolBar()), new Properties());
//            File file = new File("d:/intersys/IntersysNFe/IntersysNFe_fat.jar");
//            File file = new File("d:/osgi_estudos/plugins/OSGIBundle_1.0.0.jar");
//            File file = new File("../SimpleBundle/dist/SimpleBundle.jar");            
            File file = new File("D:/ccomin/workspace/j2se/DeploySystextilWeb-Plugin/dist/DeploySystextilWeb-Plugin.jar"); 
            long idBundle = framework.getBundleId(file.toURI().toURL().toString());
            if (idBundle == -1) {
                idBundle = framework.installBundle(file.toURI().toURL().toString(), new FileInputStream(file));
                framework.startBundle(idBundle);
            } else {
                System.out.println("atualizando....");
                framework.updateBundle(idBundle);
                framework.startBundle(idBundle);
                System.out.println("atualizado!");
            }
//            framework.startBundle(idBundle);
//            framework.stopBundle(idBundle);
//            framework.uninstallBundle(idBundle);
            framework.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
